#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

int n, m , k;

string name[N];
map<string,string> mp;
string find(string x){
    if(mp[x] != x)return mp[x] = find(mp[x]);
    return x;
}

void merge(string x,string y){
    string xx = find(x);
    string yy = find(y);
    if( xx != yy)mp[xx] = yy;
}

int main()
{
    cin >> n >> m;
    for(int i = 1; i<= n; i++){
        string x;
        cin >> x;
        mp[x] = x;
    }

    for(int i = 1; i<= m; i++){
        string x,y;
        cin >> x >> y;
        merge(x,y);
    }

    cin >> k;
    for(int i = 1; i<= k; i++){
        string x,y;
        cin >> x >> y;
        if(find(x) != find(y))cout << "No.\n";
        else cout << "Yes.\n";
    }

   
   return 0;
}
